clear all; % removes all variables, globals, functions and MEX links.
close all; % closes all the open figure windows.
clc; % clears the command window and homes the cursor.

% file_name1 = 'C:\Users\XRQ\Desktop\XRQ-Thesis-CAS-2016\program\preprocessing\acceleration_data\raw_acceleration_data_file_right_xrq_11';
% file_name2 = 'C:\Users\XRQ\Desktop\XRQ-Thesis-CAS-2016\program\preprocessing\acceleration_data\removed_dc_offset_data_file_right_xrq_11';
% file_name3 = 'C:\Users\XRQ\Desktop\XRQ-Thesis-CAS-2016\program\preprocessing\acceleration_data\moving_average_filtered_data_file_right_xrq_11';

file_name1 = 'C:\Users\XRQ\Desktop\XRQ-Thesis-CAS-2016\program\preprocessing\acceleration_data\raw_acceleration_data_file_left_wyd_8';
file_name2 = 'C:\Users\XRQ\Desktop\XRQ-Thesis-CAS-2016\program\preprocessing\acceleration_data\removed_dc_offset_data_file_left_wyd_8';
file_name3 = 'C:\Users\XRQ\Desktop\XRQ-Thesis-CAS-2016\program\preprocessing\acceleration_data\moving_average_filtered_data_file_left_wyd_8';

[raw_acceleration_data_x, raw_acceleration_data_y, raw_acceleration_data_z, sample_time_1] = acceleration_acquisition(file_name1);
[removed_dc_offset_data_x, removed_dc_offset_data_y, removed_dc_offset_data_z, sample_time_2] = acceleration_acquisition(file_name2);
[moving_average_filtered_data_x, moving_average_filtered_data_y, moving_average_filtered_data_z, sample_time_3] = acceleration_acquisition(file_name3);


figure;
plot(sample_time_1, raw_acceleration_data_x, '-', sample_time_1, raw_acceleration_data_y, '--', sample_time_1, raw_acceleration_data_z, '-.', 'LineWidth', 2);
xlim([0 1.1]);
xlabel('Time (s)');
ylabel('Acceleration (g)');
legend('x', 'y', 'z');

figure;
plot(sample_time_2, removed_dc_offset_data_x, '-', sample_time_2, removed_dc_offset_data_y, '--', sample_time_2, removed_dc_offset_data_z, '-.', 'LineWidth', 2);
xlim([0 1.1]);
xlabel('Time (s)');
ylabel('Acceleration (g)');
legend('x', 'y', 'z');

figure;
plot(sample_time_3, moving_average_filtered_data_x, '-', sample_time_3, moving_average_filtered_data_y, '--', sample_time_3, moving_average_filtered_data_z, '-.', 'LineWidth', 2);
xlim([0 1.1]);
xlabel('Time (s)');
ylabel('Acceleration (g)');
legend('x', 'y', 'z');


[f1, acceleration_raw_x_fft_abs] = my_fft(raw_acceleration_data_x, 128);
[f2, acceleration_maf_x_fft_abs] = my_fft(moving_average_filtered_data_x, 128);
figure;
subplot(2, 1, 1);
plot(f1(1:length(f1)/2), acceleration_raw_x_fft_abs(1:length(acceleration_raw_x_fft_abs)/2), 'LineWidth', 2);
xlabel({'Frequency (Hz)', '(1)'});
ylabel('Amplitude');
subplot(2, 1, 2);
plot(f2(1:length(f2)/2), acceleration_maf_x_fft_abs(1:length(acceleration_maf_x_fft_abs)/2), 'LineWidth', 2);
xlabel({'Frequency (Hz)', '(2)'});
ylabel('Amplitude');